package com.controller;

import com.entity.School;
import com.service.SchoolService;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Data
@RestController
@RequestMapping("/school")
@CrossOrigin
public class SchoolController {
    @Autowired
    private SchoolService schoolService;

    // 查询所有学校信息
    @GetMapping
    public List<School> selectAllSchools() {
        return schoolService.selectAllSchools();
    }

    // schoolName 查询学校信息
    @GetMapping(params = "schoolName")
    public List<School> selectSchoolBySchoolName(String schoolName) {
        return schoolService.selectSchoolBySchoolName(schoolName);
    }

    // id 查询学校信息
    @GetMapping("/{schoolId}")
    public School selectSchoolBySchoolId(@PathVariable String schoolId) {
        return schoolService.selectSchoolBySchoolId(Integer.parseInt(schoolId));
    }

    // id 删除学校信息
    @DeleteMapping("/{schoolId}")
    public int deleteSchoolBySchoolId(@PathVariable String schoolId) {
        return schoolService.deleteSchoolBySchoolId(Integer.parseInt(schoolId));
    }

    // 新增学校信息
    @PostMapping
    public int insertSchool(@RequestBody School school) {
        return schoolService.insertSchool(school );
    }

    // 修改学校信息
    @PutMapping
    public int updateSchool(@RequestBody School school) {
        return schoolService.updateSchool(school);
    }
}
